## 
## The downloaded binary packages are in
##  /var/folders/gs/080wb67j58df5y8ccjf53yw00000gn/T//RtmpelCG7i/downloaded_packages
## 
## The downloaded binary packages are in
##  /var/folders/gs/080wb67j58df5y8ccjf53yw00000gn/T//RtmpelCG7i/downloaded_packages
## 
## The downloaded binary packages are in
##  /var/folders/gs/080wb67j58df5y8ccjf53yw00000gn/T//RtmpelCG7i/downloaded_packages
## Error in get(genname, envir = envir) : object 'testthat_print' not found

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

## Warning: Missing column names filled in: 'X1' [1]
## 
## ── Column specification ─────────────────────────────────────────────────────────────────────────────────────────────────
## cols(
##   .default = col_double(),
##   INSTNM = col_character(),
##   CITY = col_character(),
##   STABBR = col_character(),
##   ZIP = col_character(),
##   UNEMP_RATE = col_logical(),
##   DEBT_MDN = col_character(),
##   MN_EARN_WNE_P10 = col_logical(),
##   MD_EARN_WNE_P10 = col_logical(),
##   ADM_RATE_ALL_1 = col_character()
## )
## ℹ Use `spec()` for the full column specifications.
## # A tibble: 1,269 x 24
##       X1 UNITID INSTNM CITY  state ZIP     lat  long ADM_RATE CONTROL ACTCMMID
##    <dbl>  <dbl> <chr>  <chr> <chr> <chr> <dbl> <dbl>    <dbl>   <dbl>    <dbl>
##  1     0 100654 Alaba… Norm… AL    35762  34.8 -86.6    0.899       1       18
##  2     1 100663 Unive… Birm… AL    3529…  33.5 -86.8    0.921       1       25
##  3     3 100706 Unive… Hunt… AL    35899  34.7 -86.6    0.809       1       28
##  4     4 100724 Alaba… Mont… AL    3610…  32.4 -86.3    0.977       1       18
##  5     5 100751 The U… Tusc… AL    3548…  33.2 -87.5    0.591       1       27
##  6     7 100830 Aubur… Mont… AL    3611…  32.4 -86.2    0.928       1       21
##  7     8 100858 Aubur… Aubu… AL    36849  32.6 -85.5    0.754       1       28
##  8     9 100937 Birmi… Birm… AL    35254  33.5 -86.9    0.567       2       26
##  9    10 101189 Faulk… Mont… AL    3610…  32.4 -86.2    0.523       2       21
## 10    14 101435 Hunti… Mont… AL    3610…  32.4 -86.3    0.584       2       22
## # … with 1,259 more rows, and 13 more variables: SAT_AVG <dbl>, COSTT4_A <dbl>,
## #   UNEMP_RATE <lgl>, DEBT_MDN <chr>, MN_EARN_WNE_P10 <lgl>,
## #   MD_EARN_WNE_P10 <lgl>, UGDS_WHITE <dbl>, UGDS_BLACK <dbl>, UGDS_HISP <dbl>,
## #   UGDS_ASIAN <dbl>, UGDS_AIAN <dbl>, UGDS_NHPI <dbl>, ADM_RATE_ALL_1 <chr>
##  [1] "X1"              "UNITID"          "INSTNM"          "CITY"           
##  [5] "state"           "ZIP"             "lat"             "long"           
##  [9] "ADM_RATE"        "CONTROL"         "ACTCMMID"        "SAT_AVG"        
## [13] "COSTT4_A"        "UNEMP_RATE"      "DEBT_MDN"        "MN_EARN_WNE_P10"
## [17] "MD_EARN_WNE_P10" "UGDS_WHITE"      "UGDS_BLACK"      "UGDS_HISP"      
## [21] "UGDS_ASIAN"      "UGDS_AIAN"       "UGDS_NHPI"       "ADM_RATE_ALL_1" 
## [25] "uni_rank"
# | variable                 | description                                               |
# | :----------------------- | --------------------------------------------------------- |
# | UNITID                   | IPEDS Unit ID                                             |   
# | CITY                     | description                                               |
# | state                    | state                                                     |
# | DEBT_MDN                 | The median original amount of the                         |
# |                          | loan principal upon entering repayment                    |

Selectivity is based on Conwell et al. (2022 exp.) [1]

Including Plots

#note 
us <- map_data("state")
us_states <- as_data_frame(us) %>% dplyr::rename(state=region)
us_states
## # A tibble: 15,537 x 6
##     long   lat group order state   subregion
##    <dbl> <dbl> <dbl> <int> <chr>   <chr>    
##  1 -87.5  30.4     1     1 alabama <NA>     
##  2 -87.5  30.4     1     2 alabama <NA>     
##  3 -87.5  30.4     1     3 alabama <NA>     
##  4 -87.5  30.3     1     4 alabama <NA>     
##  5 -87.6  30.3     1     5 alabama <NA>     
##  6 -87.6  30.3     1     6 alabama <NA>     
##  7 -87.6  30.3     1     7 alabama <NA>     
##  8 -87.6  30.3     1     8 alabama <NA>     
##  9 -87.7  30.3     1     9 alabama <NA>     
## 10 -87.8  30.3     1    10 alabama <NA>     
## # … with 15,527 more rows
mapping=aes(x = lat, y = long)
ggplot(us,  aes(x = long, y = lat, group=group)) +
  geom_polygon(aes(), color='white') + 
  theme_ipsum() + theme(panel.grid = element_blank())+ geom_point(data = df, aes(x = long, y = lat, group=UNITID),color='orange',alpha=0.5) 

dfsub <- df %>% subset(DEBT_MDN != 'PrivacySuppressed') %>% drop_na(uni_rank) %>% drop_na(DEBT_MDN)
dfsub$uni_rank_cat = factor(dfsub$uni_rank, levels=c('elite','highly selective','selective','less selective','not selective'))

ggplot(dfsub, aes(x=uni_rank_cat,y=DEBT_MDN)) +
  geom_point(color = '#87495F',alpha=.12) +
  theme_ipsum(base_size = 12, axis_title_size = 14) +
  theme(
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank()) +
      ggtitle("Student Debt and School Tiers") +    
  labs(fill = "Selectivity", y="Student Debt", x = "School Competitiveness")

#dfsub %>% group_by(uni_rank) %>% mutate(density = n()) 

m <- ggplot(dfsub, aes(x=DEBT_MDN,y=UGDS_BLACK, color = uni_rank_cat)) +
  geom_point(aes(color = uni_rank_cat), alpha=.5) +
  scale_color_manual(values=c("#F7F5F4","#786D77","#82809A","#87495F","#211622"))+
  geom_smooth(method = lm, se = FALSE)+
  theme_ipsum() +
  theme(
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank()) +
      ggtitle("Student Debt and Racial Composition (Black Students)") +    
  labs(y="% Black Students", x = "Median Student Debt ($)")
ggplotly(m)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

[1] - Conwell, Jordan A. and Natasha Quadlin. Forthcoming. “Race, Gender,Higher Education, and Socioeconomic Attainment: Evidence from Baby Boomers at Mid-Life.” Social Forces. DOI: 10.1093/sf/soab010.